package com.larry.mapreduce.combiner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @ProjectName MapReduceDemo
 * @Author larry
 * @Date 23:38 2021/11/6
 * @Description TODO
 *
 * KEYIN---输入键
 * VALUEIN---输入值
 * KEYOUT---输出键
 * VALUEOUT---输出值
 *
 **/
public class WordCountMapper extends Mapper<LongWritable, Text,Text, IntWritable> {

    private Text outK = new Text();
    private IntWritable outV = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //获取一行
        String line = value.toString();
        //切割单词
        String[] words = line.split(" ");
        //循环写出
        for (String word : words) {
            //设置key
            outK.set(word);
            //写出
            context.write(outK,outV);
        }

    }
}
